const { default: mongoose } = require("mongoose");
let mongo = require("./db");

// 职务字段
const dutie = mongo.Schema({ name: String });

// 学院字段
const college = mongo.Schema({ name: String });

// 班级
const clas = mongo.Schema({
  name: String, //姓名
  cid: { type: mongoose.Types.ObjectId, ref: "class" }, //上级班级
});

// 用户字段
const user = mongo.Schema({
  name: String, //姓名
  password: String, //密码
  img: { type: String, default: "" }, //头像
  phone: { type: String, default: "" }, //电话
  email: { type: String, default: "" }, //邮箱
  class: { type: mongoose.Types.ObjectId, ref: "class" }, //班级id
  college: { type: mongoose.Types.ObjectId, ref: "college" }, //学院_id
  dutie: { type: mongoose.Types.ObjectId, ref: "dutie" }, //职务_id
});


// 请假类型字段
const type = mongo.Schema({
  name: String, //请假类型
})

// 请假条字段
const data = mongo.Schema({
  student:{type:mongoose.Types.ObjectId,ref:'user'},//学生
  type:{type:mongoose.Types.ObjectId,ref:'type'}, //请假类型
  fdate:{type:Date,default:Date.now},//申请时间
  sdate:{type:Date,default:Date.now},//开始时间
  rdate:{type:Date,default:Date.now},//结束时间
  opin:{type:String,default:''},//申请建议
  state:{type:Number,default:0}, //批假状态0审核中，1申请成功，2申请失败
  tuser:{type:mongoose.Types.ObjectId,ref:'user'} //批审人
});

// 职务
const duties = mongo.model("dutie", dutie, "dutie");

// 学院
const colleges = mongo.model("college", college, "college");

// 班级
const classes = mongo.model("class", clas, "class");

// 用户
const users = mongo.model("user", user, "user");

// 类型
const types = mongo.model("type", type, "type");

// 请假数据
const datas = mongo.model("data", data, "data");

module.exports = {
  duties,colleges,classes,users,types,datas
};
